< previous page page_795 next page >

Page 795
The Parts of the SQL Statement
A SQL statement consists of three parts:
Parameter declarationsThese are optional parameters that are passed to the SQL statement by the program.
The manipulative statementThis part of the statement tells the Query engine what kind of action to take, such as SELECT or DELETE.
Options declarationsThese declarations tell the Query engine about any filter conditions, data groupings, or sorts that apply to the data being processed. These include the WHERE, GROUP BY, andORDER BY clauses.
These parts are arranged as follows:
[Parameters declarations] Manipulative statement [options]
The parameters declaration section is where you define any parameters used in the SQL statement. Any values defined in the parameters declaration section are assigned before the SQL statement is executed.
Most of this chapter uses only the manipulative statement and the options declarations. Using these two parts of the SQL statement, you can create queries to perform a wide variety of tasks. Table C.1 lists four of the manipulative clauses and their purposes.
Table C.1 Parts of the Manipulative Statement
StatementFunction
DELETE FROMRemoves records from a table
INSERT INTOAdds a group of records to a table
SELECTRetrieves a group of records and places the records in a dynaset or table
UPDATESets the values of fields in a table

Although manipulative statements tell the database engine what to do, the options declarations tell it what fields and records to process. The discussion of the optional parameters makes up the bulk of this chapter. In this chapter, you first look at how the parameters are used with the SELECT statement and then you apply the parameters to the other manipulative statements. Many of the examples in this chapter are based on the sales-transaction table of a sample database that might be used to manage an aquarium business.
The following discussions of the different SQL statements show just the SQL statement syntax. Be aware that these statements can't be used alone in Visual Basic. The SQL statement is always used to create a QueryDef, to create a dynaset or snapshot using the Execute method, or as the RecordSource property of a data control. This section explains the part of a SQL statement. Later in the appendix, the "Using SQL" section explains how these statements are actually used in code.

 
< previous page page_795 next page >